function decodeTime(str) {
    let arr = [];
    arr[0] = str.charAt(0);
    arr[1] = str.charAt(1);
    arr[2] = str.charAt(3);
    arr[3] = str.charAt(4);
    arr = arr.map(Number);
    let time;
    let min = 9999;
    let minMaxTime = Number.MAX_SAFE_INTEGER;
    let result;
    const errorTime = parseInt(str.substring(0,2) + str.substring(3))
    for(let i = 0; i < arr.length; i++) {
        if(arr[i] > 2) {
            continue;
        }
        for(let j = 0; j < arr.length; j++) {
            if(arr[i] === 2 && arr[j] > 3){
                continue;
            }
            for(let n = 0; n < arr.length; n++) {
                if(arr[n] >= 6) {
                    continue
                }
                for(let m = 0; m < arr.length; m++) {
                    time = parseInt(''+arr[i]+arr[j]+arr[n]+arr[m]);
                    if(time < errorTime) {
                        min = Math.min(min, time)
                    } else if(time > errorTime) {
                        minMaxTime = Math.min(minMaxTime, time);
                    }
                }
            }
        }
    }
    if(minMaxTime === Number.MAX_SAFE_INTEGER) {
        result = String(min);
    } else {
        result = String(minMaxTime);
    }
    console.log(result.substring(0,2) + ':' + result.substring(2))
}
decodeTime('03:02')
console.log(parseInt('0'))